<?php
namespace app\admin\controller;
use think\Controller;
use think\Validate;
use think\Db;
use think\Session;
class Project extends Basic
{  

	//
    public function label()
    {
     $label= Db::name('vehicle_label')->where('types','1')->paginate(10);
	 $this->assign('label',$label); 
     return $this->fetch();
    }
	 public function labelxg()
    {//修改
		 $post=input("post.");
			       
		if($post){
		  $id=$post['id'];unset($post['id']);
		   $fin=Db::name('vehicle_label')->where('id',$id)->find();
           if(!$fin){ $this->success('该分类不存在');}
		   Db::name('vehicle_label')->where('id',$id)->update($post);
		   $this->success('操作成功！');
		}else{
     $id=input('param.id');
    $user= Db::name('vehicle_label')->where('id',$id)->find();
	
	 $userdj=Db::name('memberdj')->where('state','1')->select();
	 $this->assign('userf',$user);
     $this->assign('userdj',$userdj);
     return $this->fetch();
	   }
    }
	 public function labeladd()
    {//添加
		 $post=input("post.");
			       
		if($post){

		   $fin=Db::name('vehicle_label')->where(array('type'=>$post['type'],'types'=>$post['types']))->find();
		   //dump($fin);die;
           if($fin){ $this->success('该分类已存在');}
		   $post['addtime']=date("Y-m-d H:i:s");
		   $insert=Db::name('vehicle_label')->insert($post);
		   $this->success('操作成功！');
		}else{
     $id=input('param.id');
  
	
	 $this->assign('id',$id); 
     return $this->fetch();
	   }
    }
	public function labelde()
    {//删除
		 $post=input("param.");
			       
		if($post){
		  $id=$post['id'];unset($post['id']);
		  $fin=Db::name('vehicle_label')->where('id',$id)->find();
           if(!$fin){ $this->success('该分类不存在');}
		   Db::name('vehicle_label')->where('id',$id)->delete();
		   $this->success('操作成功！');
		}
    }


    //
	
	 public function classification()
    {
     $label= Db::name('vehicle_label')->where('types','2')->paginate(10);;
	 $this->assign('label',$label); 
     return $this->fetch();
    } 
	 public function dealer()
    {
      $label= Db::name('vehicle_label')->where('types','3')->paginate(10);;
	 $this->assign('label',$label); 
     return $this->fetch();
    
    }
	 public function release()
    {

     $post=input("post.");
			       
		if($post){
			//dump($post);die;
			 $up=upload('photo_file');
		   if(!empty($up['error'])){
		   $this->error($up['error']);
		   
		   }
		   if($up){
		    $post['photo_img']=$up;
		   }else{
		    $this->error('图片不能为空');
		   }
		   if($post['title']==''){$this->error('项目名称不能为空！');}
		   if($post['cheshang_id']==''){$this->error('项目分类不能为空！');}
		   if($post['money']==''){$this->error('项目规模不能为空！');}
		   //if($post['audit']!='1' and $post['audit']!='0' ){$this->error('请选择线上线下！');}
		  
		 
			unset($post['editorValue']);
			$post['addtime']=date("Y-m-d H:i:s");
		   $insert=Db::name('project')->insert($post);
		   $this->success('操作成功！');
		}else{
			
		  $label= Db::name('vehicle_label')->where('types','1')->select();
        
	      $this->assign('label1',$label);
         
		  $zcconfig=Db::name('zcconfig')->find();
		   $this->assign('zcconfig',$zcconfig);
         return $this->fetch();
	 
	   }
    }
  public function dearticle(){
      $post=input("param.");
	  $id=$post['id'];
	  $de=Db::name('project')->where('id',$post['id'])->delete();
	  if($de){ $this->success('操作成功！');}else{
	   $this->error('操作失败！');
	  }

  }

	 public function prdjeup()
    {//修改项目

     $post=input("post.");
			       
		if($post){
			//dump($post);die;
			 $up=upload('photo_file');
		   if(!empty($up['error'])){
		   $this->error($up['error']);
		   
		   }
		   if($up){
		    $post['photo_img']=$up;
		   }else{
		    //$this->error('图片不能为空');
			unset($post['photo_img']);
		   }
		   if($post['title']==''){$this->error('项目名称不能为空！');}
		   if($post['cheshang_id']==''){$this->error('项目分类不能为空！');}
		   if($post['money']==''){$this->error('项目规模不能为空！');}
		
		
		   if($post['days']=='' or $post['days']<1){$this->error('项目期限错误');}
			unset($post['editorValue']);
			
			
		   $update=Db::name('project')->where('id',$post['id'])->update($post);
		   $this->success('操作成功！');
		}else{
		  $label= Db::name('vehicle_label')->where('types','1')->select();
        $post=input("param.");
	      $this->assign('label1',$label);
          
		  $zcconfig=Db::name('project')->where('id',$post['id'])->find();
		   $this->assign('zcconfig',$zcconfig);
         return $this->fetch();
	 
	   }
    }
	
	 public function zhongchouz()
    {

    $label= Db::name('vehicle_label')->where('types','1')->select();
        
	     
      $project= Db::name('project')->paginate(10);;
	  $arr=array();
	  foreach($label as $vk){
	   $arr[$vk['id']]=$vk['type'];
	  }
	   $this->assign('arr',$arr);
	 $this->assign('project',$project);
	  return $this->fetch();
    }

	 public function projectab()
    {

    //众筹中订单资料
	    
	      $post=input("param.");
         
          $order=Db::name('orderlist')->alias('a')->join('__PROJECT__ w','a.projectid=w.id')->join('__MEMBER__ c','a.userid=c.id')->where('projectid',$post['id'])->field('a.*,c.mobile,c.realname,w.title')->paginate(10);;
		  $wc='';
          if(!empty($post['wc'])){
		  $wc=$post['wc'];
		  }
		   $this->assign('wc',$wc);
		  $this->assign('order',$order);
		 
	  return $this->fetch();
    }

	 public function sale()
    {
		 $date['status']='2';
		 $date['sflb']='0';
		 $date['sfhg']='0';

       $project= Db::name('project')->where($date)->paginate(10);;
	 $this->assign('project',$project);
	  return $this->fetch();
    }
	

	
	

	 public function statistics()
    {

     return $this->fetch();
    }
	 public function order()
    {
		  $post=input("param.");
		  if(!empty($post['id']) or !empty($post['uid'])){
			  $sql=" 1=1 ";
			  if(!empty($post['id'])){$sql.=" and projectid='".$post['id']."' ";}
			   if(!empty($post['uid'])){$sql.=" and userid='".$post['uid']."' ";}
              $money=Db::name('orderlist')->alias('a')->join('__PROJECT__ w','a.projectid=w.id')->join('__MEMBER__ c','a.userid=c.id')->field('a.*,c.mobile,c.name,w.days,w.fenhong,c.realname,w.title')->where($sql)->paginate(10);;
		  }else{
		    if(empty($post['id']) and empty($post['uid'])){
              $money=Db::name('orderlist')->alias('a')->join('__PROJECT__ w','a.projectid=w.id')->join('__MEMBER__ c','a.userid=c.id')->field('a.*,c.mobile,c.name,w.days,w.fenhong,c.realname,w.title')->paginate(10);;
		    }
		  }
		
         $this->assign('order',$money);
		  
     return $this->fetch();
    }
	   public function orderdel(){
      $post=input("param.");
	  $id=$post['id'];
	  $de=Db::name('orderlist')->where('id',$post['id'])->delete();
	  if($de){ $this->success('操作成功！');}else{
	   $this->error('操作失败！');
	  }

  }
}
